package zone.czh.woi.woim.base.channel.adapter;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelOutboundHandler;
import io.netty.handler.codec.MessageToMessageDecoder;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import zone.czh.woi.base.util.Pair;
import zone.czh.woi.protocol.protocol.Payload;

import java.util.List;

/**
*@ClassName: ProtocolAdapter
*@Description: None
*@author woi
*/
@AllArgsConstructor
public abstract class ProtocolAdapter<T> extends MessageToMessageDecoder<T>{
    @Getter
    @Setter
    protected String protocolName;

    @Override
    final protected void decode(ChannelHandlerContext ctx, T t, List<Object> out) throws Exception {
        out.add(parse(ctx,t));
    }

    abstract protected Payload parse(ChannelHandlerContext ctx, T t);

    abstract public Object encode(ChannelHandlerContext ctx,Payload payload);

    abstract public List<Pair<String,ChannelInboundHandler>> getDecoders();

    abstract public List<Pair<String,ChannelOutboundHandler>> getEncoders();
}
